﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StatisticWord.Question;

namespace StatisticWord.Answer
{
    public class Effie : IStatisticWord
    {

        public string IStatisticWord(string str)
        {
            string[] current = str.Split(new string[] { ",","?","\"","."," "}, StringSplitOptions.RemoveEmptyEntries);
            List<string> wordlist = new List<string>();
            int[] counts = new int[current.Length];
            int m = 0;
            string output=null;
            for (int i = 0; i < current.Length; i++)
            {
                bool flag=false;
                int j=0;
                for (j=0;j<wordlist.Count;j++)
                {
                if (string.Compare(current[i],wordlist[j],true)==0)
                 {
                       flag=true;
                       counts[j] += 1;
                   }
               }
               if (!flag)
               {
                   wordlist.Add(current[i]);
                   counts[m] = 1;
                   m = m + 1;
               }
            }
            for (int n = 0; n < wordlist.Count; n++)
            {
                output += wordlist[n] + ":" + counts[n] + ";";
            }

            return output;
        }
    }
}
